using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using Mahjong.UI;


namespace Mahjong.UI
{
public class BaseUI : MonoBehaviour
{
    private Base baseLogic;

    public void SetBaseLogic(Base baseLogic)
    {
        this.baseLogic = baseLogic;
    }
    //加载游戏大厅界面的逻辑/*暂时先用的牌桌图片*/
    public void LoadLobbyScene(Dictionary<int, string> playerInfo)
    {
        Debug.Log("Loading Lobby Scene...");
         // 加载背景图片
        Image backgroundImage = GameObject.Find("Background").GetComponent<Image>();
        Sprite backgroundSprite = Resources.Load<Sprite>("C:/mahjong_layout/Assets/Resources/bg.png");
        if (backgroundSprite != null)
        {
            backgroundImage.sprite = backgroundSprite;
        }
        else
        {
            Debug.LogError("Background sprite not found!");
        }

        //加载用户输入框
        GameObject inputFieldObj = Resources.Load<GameObject>("C:/mahjong_layout/Assets/Resources/shuru.png");
        if (inputFieldObj != null)
        {
            GameObject inputField = Instantiate(inputFieldObj, transform);
            InputField inputFieldComponent = inputField.GetComponent<InputField>();
            //需要强制转换为Text组件
        if (inputFieldComponent.placeholder is Text placeholderText)
        {
            placeholderText.text = "请输入人数";
        }
        }
        else
        {
            Debug.LogError("Input field prefab not found!");
        }
        //加载人物图像
        GameObject characterObj = Resources.Load<GameObject>("C:/mahjong_layout/Assets/Resources/renwu.png");
        if (characterObj != null)
        {
            Instantiate(characterObj, transform);
        }
        else
        {
            Debug.LogError("Character prefab not found!");
        }

        //通知base大厅已加载
        baseLogic.OnLobbySceneLoaded(); 
    }
    

    public void LoadTableScene(Dictionary<int, string> playerInfo)
    {
        //更新牌桌界面的逻辑
        Debug.Log("Updating Table Scene...");
         // 加载背景图片
        Image backgroundImage = GameObject.Find("Background").GetComponent<Image>();
        Sprite backgroundSprite = Resources.Load<Sprite>("bg");
        if (backgroundSprite != null)
        {
            backgroundImage.sprite = backgroundSprite;
        }
        else
        {
            Debug.LogError("Background sprite not found!");
        }
        baseLogic.OnTableSceneLoaded();
    }

    public void LoadResultsScene(Dictionary<int, int> finalScores)
    {
        //加载游戏结果界面的逻辑
        Debug.Log("Loading Results Scene...");
         // 加载背景图片
        Image backgroundImage = GameObject.Find("Background").GetComponent<Image>();
        Sprite backgroundSprite = Resources.Load<Sprite>("bg");
        if (backgroundSprite != null)
        {
            backgroundImage.sprite = backgroundSprite;
        }
        else
        {
            Debug.LogError("Background sprite not found!");
        }
        baseLogic.OnResultsSceneLoaded();
    }

    // public void LoadNewRoundScene()
    // {
    //     //加载新一轮游戏界面的逻辑
    //     Debug.Log("Loading New Round Scene...");
    //     //在这里实现具体的加载新一轮游戏界面的代码
    //     baseLogic.OnNewRoundSceneLoaded(); 
    // }
}
}


